package com.viewpagerindicator.sample.adapters;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.viewpagerindicator.sample.R;
import com.viewpagerindicator.sample.beans.Goods;
import com.viewpagerindicator.sample.beans.GoodsType;

import org.json.JSONObject;

import java.util.List;


/**
 * Created by zhao on 2015/11/7.
 */
public class TypeListAdapter extends ArrayAdapter<GoodsType> {
    private int resource;
    private LayoutInflater inflater;
    public TypeListAdapter(Context context, int resource, List<GoodsType> objects) {
        super(context, resource, objects);
        this.resource=resource;
        this.inflater=LayoutInflater.from(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView = inflater.inflate(resource, null);
        }
        TextView textView= (TextView) convertView.findViewById(R.id.type_item_name);
        textView.setText(getItem(position).getName());
        TextView descTextView= (TextView) convertView.findViewById(R.id.type_item_desc);
        descTextView.setText(getItem(position).getDesc());
        convertView.setTag(getItem(position).getId());
        return convertView;
    }
}
